
import { Module, OnModuleInit } from '@nestjs/common';
import { WechatGatewayService } from './wechat.gateway.service'
import { ChatController } from './chat.controller';
import { LongConnsService } from './long.conns.service';
import { AuthGuard } from '@utils/SHA256_token_auth.guard'
import { RedisService } from './redis.service';
import { PushKafkaService } from './push.kafka.service';
import { TransferKafkaService } from './transfer.kafka.service';
import { ChatCoreService } from './chat.core.service';
import { GeweReceiverController } from './gewe.receiver.controller';
import { MongoService } from './mongo.service';
import { MsgService } from './msg.service';
import { StorageService } from './storage.service';
import { QueryService } from './query.service';

@Module({
    controllers: [ChatController,GeweReceiverController],
    providers: [
        WechatGatewayService,
        LongConnsService,
        AuthGuard,
        RedisService,
        PushKafkaService,
        TransferKafkaService,
        ChatCoreService,
        MongoService,
        MsgService,
        StorageService,
        QueryService
    ],
    exports: [LongConnsService]
})

export class WechatGatewayModule implements OnModuleInit {

    kafkaHost: string = '134.175.224.228:9092'

    async onModuleInit() {
        // const kafka = new Kafka({
        //     logLevel: logLevel.INFO,
        //     brokers: [`${this.kafkaHost}`],
        //     clientId: 'wechat-gateway-module',
        // });

        // const run = async () => {
        //     await kafka.admin().connect()

            // await kafka.admin().deleteTopics({
            //     topics :[
            //         'MsgToPush',
            //         'MsgToMongo',
            //         'latestMsgToRedis'
            //     ]
            // })

        //     await kafka.admin().deleteTopicRecords({
        //         topic: 'latestMsgToRedis',
        //         partitions: [{ partition: 0, offset: '-1' }]
        //     })

        //     await kafka.admin().deleteTopicRecords({
        //         topic: 'MsgToPush',
        //         partitions: [{ partition: 0, offset: '-1' }]
        //     })

        //     await kafka.admin().deleteTopicRecords({
        //         topic: 'MsgToMongo',
        //         partitions: [{ partition: 0, offset: '-1' }]
        //     })

        //     await kafka.admin().disconnect()
        // }


        // run().catch(async (e) => {
        //     await kafka.admin().disconnect()
        //     console.log(e)
        // })
    }
}
